<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" isELIgnored="false"%>
<%@ include file="/WEB-INF/views/shared/taglib.jsp"%>
<%
	request.setAttribute("title", "意见反馈");
%>

<%@ include file="/WEB-INF/views/shared/master/weContentHeader.jsp"%>
<style type="text/css"> 
	body{
		background-color: #f5f5f5;
	}
	
	.bottom-btn{
		background-color:#2196F3;
	}
	.forInput{
		color: #666;
		padding-top:15px;
		padding-bottom:15px;
		font-family: 幼圆;
		margin-bottom: 13px;
		background-color: #fff;
		width: 100%;
		text-indent:15px;
	}
	.forInput::-webkit-input-placeholder{
		color: #999;
	}
	.weui-cell:before{
		border-top: 0px;
	}
</style>
<%@ include file="/WEB-INF/views/shared/master/weTitle.jsp"%>
<div class="goback" data-back-point="personCenter"></div>
<div style="text-align: center;margin-bottom: 1rem">
	<a href="<c:url value='/wechat/cust/adviceFeedback/feedbackList'/>"><p style="text-align: right;padding: 10px;color: #2196F3">反馈记录</p></a>
	<img  style="width: 20%;margin-top: 1rem;" src="<c:url value='/images/we/cust/idea.png' />">
	<P style="color: #666">您的宝贵意见将帮助我们不断改进</P>
</div>

<form id="submitAdvice" action="<c:url value='/wechat/cust/adviceFeedback/submitAdvice'/>" method="post">
	<textarea class="weui-textarea forInput adviceTextarea" placeholder="请阐述您的意见" rows="5" id="advice" onBlur="checkAdvice()"></textarea>
	<input step="padding:15px;" class="weui-input forInput" type="number" placeholder="留下您的qq、手机号或者微信" name="contact" id="contact" onBlur="checkContact()"></input>
	<input type="hidden" name="advice" class="advice" />
	
</form>

<div class="weui-cell btn-cell">
	<div class="weui-cell__bd">
		<Button class="weui-btn weui-btn_primary bottom-btn" type="button" onclick="submitAdvice()">提交</Button>
	</div>
</div>

<%@ include file="/WEB-INF/views/shared/scripts/jquery.jsp"%>
<%@ include file="/WEB-INF/views/shared/scripts/jqweui.jsp"%>
<%@ include file="/WEB-INF/views/shared/scripts/tabmob.jsp"%>


<script type="text/javascript">
	
function submitAdvice(){
	if(!checkInput()){
		return;
	}
	$(".advice").val(utf16toEntities( $(".adviceTextarea").val()));
	var formData = $("#submitAdvice").serialize();
	var action = $("#submitAdvice").attr("action");
	var result = $.getTextPost(action,formData);
	if(result=="true"){
		$.toast("提交成功");
		setTimeout(function(){
			window.location.href=$.getVirtualPath()+"/wechat/cust/adviceFeedback/feedbackList";
		},500);
	}else{
		$.toast("提交失败","forbidden");
	}
}
	
	/* 判断反馈建议是否为空 */
	function checkAdvice(){
		var advice = $("#advice").val();
		if($.isNull(advice)){
			$.toptip("请输入反馈意见","error");
			return false;
		}		
		return true;
	}
	
	
	/*判断联系方式是否为空*/
	function checkContact(){
		var contact = $("#contact").val();
		if($.isNull(contact)){
			$.toptip("请输入联系方式");
			return false;
		}
		return true;
	}
	
	/* 检查所有输入 */
	function checkInput(){
		if(checkAdvice()&&checkContact()){
			return true;
		}
		return false;
	}
	

	//十六位转八位,利于存储表情
	function utf16toEntities(str) {
            var patt=/[\ud800-\udbff][\udc00-\udfff]/g;
            // 检测utf16字符正则
            str = str.replace(patt, function(char){
                var H, L, code;
                if (char.length===2) {
                    H = char.charCodeAt(0);
                    // 取出高位
                    L = char.charCodeAt(1);
                    // 取出低位
                    code = (H - 0xD800) * 0x400 + 0x10000 + L - 0xDC00;
                    // 转换算法
                    return "&#" + code + ";";
                } else {
                    return char;
                }
            });
            return str;
        }
	//八位转十六位，利于展示表情
	function entitiestoUtf16(str){
	       // 检测出形如&#12345;形式的字符串
	       var strObj=utf16toEntities(str);
	       var patt = /&#\d+;/g;
	       var H,L,code;
	       var arr = strObj.match(patt)||[];
	       for (var i=0;i<arr.length;i++){
	           code = arr[i];
	           code=code.replace('&#','').replace(';','');
	           // 高位
	           H = Math.floor((code-0x10000) / 0x400)+0xD800;
	           // 低位
	           L = (code - 0x10000) % 0x400 + 0xDC00;
	           code = "&#"+code+";";
	           var s = String.fromCharCode(H,L);
	           strObj.replace(code,s);
	       }
	       return strObj;
	   } 
	
</script>

<%@ include file="/WEB-INF/views/shared/master/weContentFooter.jsp"%>